package com.kuang.controller;

import com.kuang.pojo.AstLocalOpenWell;
import com.kuang.pojo.AstRemoteOpeningWell;
import com.kuang.service.asset.AstLocalOpenWellService;
import com.kuang.service.asset.AstRemoteOpeningWellService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
public class AstRemoteOpeningWellController {

    @Resource
    AstRemoteOpeningWellService astRemoteOpeningWellService;

    /**
     * 设备端远程开井实时 全部数据
     *
     * @param model
     * @return
     */
    @RequestMapping("getAstRemoteOpeningWells")
    public String getAstRemoteOpeningWells(Model model) {
        List<AstRemoteOpeningWell> astRemoteOpeningWells = astRemoteOpeningWellService.selectAll();
        model.addAttribute("datas", astRemoteOpeningWells);
        model.addAttribute("device_code", "");
        model.addAttribute("ver", "");
        return "mqtt/ast_remote_opening_well_list";
    }

    /**
     * 设备端远程开井实时 通过条件
     *
     * @param model
     * @return
     */
    @PostMapping("getAstRemoteOpeningWellsByExample")
    public String getAstRemoteOpeningWellsByExample(AstRemoteOpeningWell astRemoteOpeningWell, Model model) {
        List<AstRemoteOpeningWell> astRemoteOpeningWells = astRemoteOpeningWellService.selectAllByExample(astRemoteOpeningWell);
        model.addAttribute("datas", astRemoteOpeningWells);
        model.addAttribute("device_code", astRemoteOpeningWell.getDevice_code());
        model.addAttribute("ver", astRemoteOpeningWell.getVer());
        return "mqtt/ast_remote_opening_well_list";
    }

    /**
     * 获取设备信息通过id
     *
     * @param model
     * @return
     */
    @RequestMapping("getAstRemoteOpeningWellById/{id}")
    public String getAstRemoteOpeningWellById(@PathVariable("id") String id, Model model) {
        AstRemoteOpeningWell astRemoteOpeningWell = new AstRemoteOpeningWell();
        astRemoteOpeningWell.setAst_remote_opening_well_id(id);
        List<AstRemoteOpeningWell> astRemoteOpeningWells = astRemoteOpeningWellService.selectAllByExample(astRemoteOpeningWell);
        model.addAttribute("data", astRemoteOpeningWells.get(0));
        return "mqtt/ast_remote_opening_well_from";
    }


}
